/*
* Copyright (C) 2008-2009 J-P Nurmi jpnurmi@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* $Id: application.cpp 295 2009-02-17 09:10:58Z vjousse $
*/

#include "application.h"
#include "server.h"
#include "ircmodel.h"
#include "controller.h"

#include <QIcon>
#include <QMetaType>

Application::ApplicationData Application::d;

Application::Application(int& argc, char* argv[])
    : QApplication(argc, argv)
{
    setApplicationName("Communi");
    setOrganizationName("communi.googlecode.com");
    setApplicationVersion(VERSION);

    QIcon icon;
    icon.addPixmap(QPixmap(":/images/icon-16.png"));
    icon.addPixmap(QPixmap(":/images/icon-32.png"));
    icon.addPixmap(QPixmap(":/images/icon-64.png"));
    icon.addPixmap(QPixmap(":/images/icon-128.png"));
    setWindowIcon(icon);

    //qRegisterMetaType<Irc::Message>("Irc::Message");
    qRegisterMetaTypeStreamOperators<Server>("Server");
    qRegisterMetaTypeStreamOperators<ServerList>("ServerList");

	//Irc part
	model = new IrcModel(this);
	
}


/*
Connection* Application::addConnection(const Server& server, const UserInfo& user)
{
    if (connection(server, user))
        return 0;

    Connection* connection = new Connection(server, user, qApp);
    connect(connection, SIGNAL(connectedToServer()), qApp, SLOT(onConnectionStateChanged()));
    connect(connection, SIGNAL(disconnectedFromServer()), qApp, SLOT(onConnectionStateChanged()));
    connect(connection, SIGNAL(connectionError(QAbstractSocket::SocketError)), qApp, SLOT(onConnectionStateChanged()));
    d.connections += connection;
    return connection;
}

Connection* Application::connection(const Server& server, const UserInfo& user)
{
    foreach (Connection* connection, d.connections)
        if (connection->server() == server)
            return connection;
    return 0;
}

void Application::removeConnection(Connection* connection)
{
}

Connection* Application::currentConnection()
{
    return d.currentConnection;
}

void Application::setCurrentConnection(Connection* connection)
{
    if (d.currentConnection != connection)
    {
        d.currentConnection = connection;
        emit cApp->currentConnectionChanged(connection);
    }
}

void Application::onConnectionStateChanged()
{
    if (d.currentConnection == sender())
        emit currentConnectionChanged(d.currentConnection);
}
*/
